<?php
namespace Wap\Controller;
class UserOrderController extends CommonController{

	public function _initialize(){
		parent::_initialize();
		$this->user_id();
		$this->add_step('订单中心', U('index'));
	}
	// 订单列表
	public function index(){
		// $this->pagesize = 2;
		// D('Order')->pagesize = $this->pagesize;
		$type = $this->_get('type');
		switch ($type) {
			case 'all':
				$this->add_step('全部订单');
				break;
			// 待支付
			case 'wait_pay':
				$where['status'] = 'wait_pay';
				$this->add_step('待支付订单');
				break;
			// 待服务
			case 'wait_service':
				$where['status'] = array('in', 'doing-service,doing-lawyer,doing-audit');
				$this->add_step('待服务订单');
				break;
			// 待评价
			case 'wait_comment':
				$where['status']       = 'finish';
				$where['is_commented'] = 0;
				$this->add_step('待评价订单');
				break;
			
			default:
				
				break;
		}
		$this->assign('type', $type);
		// 订单号
		$order_sn = $this->_get('order_sn');
		if($order_sn){
			$where['order_sn'] = $order_sn;
		}
		$this->assign('order_sn', $order_sn);

		// 开始时间
		$start_date = $this->_get('start_date');
		if($start_date){
			$where['create_time'][] = array('egt',strtotime($start_date));
		}
		$this->assign('start_date', $start_date);


		// 结束时间
		$end_date = $this->_get('end_date');
		if($end_date){
			$where['create_time'][] = array('elt',strtotime($end_date . '23:59:59'));
		}
		$this->assign('end_date', $end_date);

		$where['user_id'] = $this->user_id;
		$list = D('Order')->get_list($where, '', $this->_get('p', '', 1));
		//处理AJAX分页
		$this->page($list, D('Order')->count);

		$this->assign('list', $list);
		$this->display();
	}
	// 订单详情
	public function detail(){
		$this->add_step('订单详情');
		$order_sn = $this->_get('order_sn', '对不起，您的操作有误！');
		$info = D('Order')->info($order_sn);

		$this->assign('info', $info);
		$this->display();
	}
}